<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/11/28
 * Time: 17:57
 */

namespace app\api\model;

class Theme extends BaseModel
{
    protected $hidden = ['update_time','delete_time', 'topic_img_id', 'head_img_id'];
    // 一对一  有外键
    public function topicImg()
    {
        return $this->belongsTo('Image', 'topic_img_id', 'id');
    }

    public function headImg()
    {
        return $this->belongsTo('Image', 'head_img_id', 'id');
    }

    // 多对多
    // （模型，中间表，中间表外键，中间表 本模型主键）
    public function book()
    {
        return $this->belongsToMany('Book', 'theme_book', 'book_id', 'theme_id');
    }


    public static function getThemesByIDs($idArray)
    {
        return self::with(['topicImg', 'headImg'])->select($idArray);
    }


    public static function getBooks($id)
    {
        return self::with(['topicImg', 'headImg', 'book'])->find($id);
    }
}